#-*- coding:utf-8 -*-

from django.db import models
from django.contrib.auth.models import User


class Bang(models.Model):
    STATUS_APPLY = 1
    STATUS_NORMAL = 2
    STATUS_DISABLED = 3
    STATUS_CHOICES = ( (STATUS_APPLY, "申请"), (STATUS_NORMAL, "正常"), (STATUS_APPLY, "禁用"),)

    owner = models.ForeignKey(User)
    name = models.CharField(max_length=100)
    desc = models.TextField()
    foundtime = models.DateTimeField(auto_now=True)
    status = models.PositiveIntegerField(choices=STATUS_CHOICES, default=STATUS_APPLY)
    membernum = models.PositiveIntegerField(default=0)

    def __unicode__(self):
        return self.name
    

class Member(models.Model):
    STATUS_APPLY = 1
    STATUS_NORMAL = 2
    STATUS_DISABLED = 3
    STATUS_CHOICES = ( (STATUS_APPLY, "申请"), (STATUS_NORMAL, "正常"), (STATUS_APPLY, "禁用"),)

    user = models.ForeignKey(User)
    bang = models.ForeignKey(Bang)
    status = models.PositiveIntegerField(choices=STATUS_CHOICES, default=STATUS_APPLY)
    ts = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.user.username


class Topic(models.Model):
    STATUS_NORMAL = 0
    STATUS_DELETED = 1
    STATUS_CHOICES = ( (STATUS_NORMAL, "正常"), (STATUS_DELETED, "删除"),)

    author = models.ForeignKey(User)
    bang = models.ForeignKey(Bang)
    title = models.CharField(max_length=100)
    content = models.TextField()
    posttime = models.DateTimeField(auto_now=True)
    reads = models.PositiveIntegerField(default=0)
    comments = models.PositiveIntegerField(default=0)
    status = models.PositiveIntegerField(choices=STATUS_CHOICES, default=STATUS_NORMAL)

    def __unicode__(self):
        return self.title


